package com.example.crm.servlet;

import com.example.crm.service.IUserService;
import com.example.crm.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/loginchk")
public class UserLoginCheckServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //获取用户请求信息
        String username=req.getParameter("username");
        String password=req.getParameter("password");
        System.out.println(username+":"+password);

        //调用service查询
        IUserService service=new UserServiceImpl();
        boolean result=service.login(username,password);

        //打印结果、跳转页面、请求转发
        if(result){
            System.out.println("登陆成功");
            resp.sendRedirect("index.jsp");
        }else {
            System.out.println("登陆失败");
            resp.sendRedirect("login.jsp");
        }
    }
}
